<?php /*a:2:{s:64:"/www/wwwroot/yinglinet.cn/app/admin/view/admin/src/roleedit.html";i:1699343572;s:57:"/www/wwwroot/yinglinet.cn/app/admin/view/base/unitjs.html";i:1699343568;}*/ ?>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>表单页面</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
</head>

<body>
    <form class="layui-form " action="" lay-filter="layui-form" id="formId">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">角色名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" value="<?php echo htmlentities((isset($msg['name']) && ($msg['name'] !== '')?$msg['name']:'')); ?>" lay-verify="name" autocomplete="off"
                            placeholder="请输入角色名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">权限选择</label>
                    <div class="layui-input-block">
                    <table class="layui-table" style="width:100%;">
        
          <thead>
           <tr>
            <th>
                 <input type="checkbox"  lay-filter="checkall" class="itemClasscheckT itemxzClasswz_qx" title="操作全选" lay-skin="primary" >
            </th>
           </tr>
           
          </thead>
          <tbody >
                <?php if(is_array($lse) || $lse instanceof \think\Collection || $lse instanceof \think\Paginator): $i = 0; $__LIST__ = $lse;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                    <tr>
                        <th>
                           <input type="checkbox" <?php if(in_array($vo['id'],$limits)): ?> checked <?php endif; ?> name="operate_id[]" lay-filter="checkTest1"   class="itemClasscheck itemClasscheck_item<?php echo htmlentities($vo['id']); ?> itemClasscheck_1" data-id="<?php echo htmlentities($vo['id']); ?>" value="<?php echo htmlentities($vo['id']); ?>" title="<?php echo htmlentities($vo['title']); ?>" lay-skin="primary" >
                        </th>
                    </tr>
                    <tr>
                        <td style="padding-left:50px;">
                          <?php if(is_array($vo['limits']) || $vo['limits'] instanceof \think\Collection || $vo['limits'] instanceof \think\Paginator): $i = 0; $__LIST__ = $vo['limits'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vi): $mod = ($i % 2 );++$i;?>
                            <input type="checkbox" <?php if(in_array($vi['id'],$limits)): ?> checked <?php endif; ?> name="operate_id[]" lay-filter="checkTest2" class="itemClasscheck itemClasscheck_item<?php echo htmlentities($vi['id']); ?>  itemClasscheck_2 itemClasscheck<?php echo htmlentities($vi['pid']); ?>_child" data-pid="<?php echo htmlentities($vi['pid']); ?>" value="<?php echo htmlentities($vi['id']); ?>" title="<?php echo htmlentities($vi['title']); ?>" lay-skin="primary" >
                          <?php endforeach; endif; else: echo "" ;endif; ?>  
                        </td>
                    </tr>
                <?php endforeach; endif; else: echo "" ;endif; ?>

          </tbody>
         </table>
                    </div>
                </div>
                
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
            <script src="/static/user/js/jquery.min.js"></script>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script>
        layui.use(['form', 'jquery'], function () {
            let form = layui.form;
            let $ = layui.jquery;

            form.on('submit(form-save)', function (data) {
                var data = $("#formId");
                postDatai("<?php echo url('admin/roleSave'); ?>?id=<?php echo htmlentities(app('request')->get('id')); ?>",data).then(function(res){
                    if (res.code==200) {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("tableId");
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2,
                            time: 1000
                        });
                    }
                });
                return false;
            });
            if(!$(`.itemClasscheck:not(:checked)`).length){
                        $(".itemxzClasswz_qx").prop("checked",true);  
                    }else{
                        $(".itemxzClasswz_qx").prop("checked",false);  
                    }
                    form.render('checkbox');     
            //全选
            form.on('checkbox(checkall)', function(obj){
                    $('.itemClasscheck_1').prop("checked",obj.elem.checked);
                    $('.itemClasscheck_2').prop("checked",obj.elem.checked);
                    form.render('checkbox');
              });
              //一级选择
              form.on('checkbox(checkTest1)', function(obj){
                    var pid=obj.value;
                    $(`.itemClasscheck${pid}_child`).prop("checked",obj.elem.checked);
                    if( !$(`.itemClasscheck${pid}_child:not(:checked)`).length ){
                            $(`.itemClasscheck_item`+pid).prop("checked",true);
                        }
                    if(!$(`.itemClasscheck:not(:checked)`).length){
                        $(".itemxzClasswz_qx").prop("checked",true);  
                    }else{
                        $(".itemxzClasswz_qx").prop("checked",false);  
                    }
                    form.render('checkbox');
              });
              //二级选择
              form.on('checkbox(checkTest2)', function(obj){
                    var pid=$(obj.elem).data("pid");
                    if(obj.elem.checked){
                        if( !$(`.itemClasscheck${pid}_child:not(:checked)`).length ){
                            $(`.itemClasscheck_item`+pid).prop("checked",true);
                        }
                        if(!$(".itemClasscheck:not(:checked)").length){
                            $(".itemxzClasswz_qx").prop("checked",true); 
                        }
                    }else{
                        $(`.itemClasscheck_item`+pid).prop("checked",false);
                        $(".itemxzClasswz_qx").prop("checked",false);  
                    }
                   
                    form.render('checkbox');
              });

  
        })
        
    </script>
    <script>








    //     参数解释  
    //  url 地址  
    //  data  数据  
    //  alt 进度提示内容  
    //  ins 0 手动处理返回信息  1 自动处理返回信息
    //     co[辅助alt  co = 0时  进度条默认关闭  co = 1时  手动关闭进度条及之后弹框的内容]


    //带文件提交
    function postDatai(url, form, alt = "", ins = 0) {
        var p = new Promise(function (resolve, reject) {
            var formData = new FormData(form[0]);
            $.ajax({
                url: url,
                type: 'POST',
                data: formData,
                dataType: 'json',
                async: true,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res.code == -1) {
                        layer.alert(res.msg, {
                            title: "提示",
                            closeBtn: 0,
                            yes: function () {
                                location.reload();
                            }
                        });
                        return;
                    }
                    if (!ins) {
                        resolve(res);
                        return;
                    }
                    layer.alert(res.msg, {
                        title: "提示",
                        closeBtn: 0,
                        yes: function () {
                            res.code == 200 ? location.reload() : layer.close(layer.index);
                            return;
                        }
                    });


                },
                error: function (e) {
                    var res = $.parseJSON(e.responseText);
                    layer.alert(res.message, {
                        title: '提示',
                        closeBtn: 0,
                    });
                },
                beforeSend: function () {
                    if (alt) {
                        layer.msg(alt, { icon: 16, shade: 0.4, time: false });
                    }

                },
                complete: function () {
                    if (alt) {
                        layer.close(layer.index);
                    }
                }

            });
        })
        return p;
    }




    //普通提交--整改
    function postData(url, data, alt = "", ins = 0, co = 0) {
        var p = new Promise(function (resolve, reject) {
            $.ajax({
                url: url,
                data: data,
                header: { 'content-type': 'application/json' },
                type: 'POST',
                dataType: 'json',
                responseType: 'text',
                success: function (res) {
                    if (res.code == -1) {
                        layer.alert(res.message, {
                            title: "提示",
                            closeBtn: 0,
                            yes: function () {
                                location.reload();
                            }
                        });
                        return;
                    }
                    if (!ins) {
                        resolve(res);
                        return;
                    }
                    layer.alert(res.message, {
                        title: "提示",
                        closeBtn: 0,
                        yes: function () {
                            res.code == 200 ? location.reload() : layer.close(layer.index);
                            return;
                        }
                    });
                },
                fail: function (res) {
                    console.log(res);

                },
                error: function (e) {
                    var res = $.parseJSON(e.responseText);
                    layer.alert(res.message, {
                        title: '提示',
                        closeBtn: 0,
                    });
                },
                beforeSend: function () {
                    if (alt) {
                        layer.msg(alt, { icon: 16, shade: 0.4, time: false });
                    }

                },
                complete: function () {
                    if (alt && co) {
                        layer.close(layer.index);
                    }
                }

            })

        })
        return p;
    }



    function getObjectURL(file) {
		var url = null;
		if (window.createObjectURL != undefined) { // basic
			url = window.createObjectURL(file);
		} else if (window.URL != undefined) { // mozilla(firefox)
			url = window.URL.createObjectURL(file);
		} else if (window.webkitURL != undefined) { // webkit or chrome
			url = window.webkitURL.createObjectURL(file);
		}
		return url;
	}
</script>
</body>

</html>